using UnityEngine;
using System.Collections;
using DG.Tweening;

public abstract class BasePanel : MonoBehaviour
{
    protected virtual void Awake()
    {

    }

    public virtual IEnumerator PlayOpenAnimation()
    {
        CanvasGroup PCG = GetComponent<CanvasGroup>();

        Transform bgTransform = transform.Find("Bg");
        CanvasGroup BCG = bgTransform.GetComponent<CanvasGroup>();

        PCG.alpha = 0f;
        BCG.alpha = 0f;

        bgTransform.localScale = new Vector3(0.5f, 0.5f, 0.5f);

        Sequence sequence = DOTween.Sequence();

        sequence.Append(PCG.DOFade(1f, 0.1f).SetEase(Ease.OutBack));
        sequence.Join(
            bgTransform.DOScale(1f, 0.25f).SetEase(Ease.OutBack)  // 背景放大
        );
        sequence.Join(
            BCG.DOFade(1f, 0.25f).SetEase(Ease.OutBack)  // 背景透明度渐变
        );
        yield return sequence.WaitForCompletion();
    }

    public virtual IEnumerator PlayCloseAnimation()
    {
        CanvasGroup PCG = GetComponent<CanvasGroup>();

        Transform bgTransform = transform.Find("Bg");
        CanvasGroup BCG = bgTransform.GetComponent<CanvasGroup>();

        Sequence sequence = DOTween.Sequence();

        sequence.Join(
            bgTransform.DOScale(0.5f, 0.3f).SetEase(Ease.InBack)
        );
        sequence.Join(
            BCG.DOFade(0f, 0.3f).SetEase(Ease.InBack)
        );
        sequence.Join(
            PCG.DOFade(0f, 0.15f).SetDelay(0.15f)
        );
        yield return sequence.WaitForCompletion();
    }

    public virtual void OnOpen()
    {
        CountdownManager.Instance.Pause();
    }
    public virtual void OnClose()
    {
        //如果倒计时没有结束，恢复倒计时
        if (CountdownManager.Instance.CurrentTime > 0)
        {
            CountdownManager.Instance.Resume();
        }
    }
}